< previous page page_278 next page >

Page 278
Next, you need to add the code that actually changes the colors in response to movements of the Slider control. You place this code, shown in Listing 12.6, in the Scroll event of the Slider controls.
Listing 12.6 SLIDERS.ZIPMoving the Slider to Change the Color of the Form
Private Sub sldColor_Scroll(Index As Integer)

    Dim nCount As Integer
    Dim lRed As Long, lGreen As Long, lBlue As Long

    'Gray is equal values of Red, Green and Blue
    If ckGray.Value = vbChecked Then
        'move all the sliders

               For nCount = 0 to 2
             sldColor(nCount).Value = sldColor(Index).Value
        Next nCount
    End If

    'Set the RGB value
    lRed = sldColor(0).Value
    lGreen = sldColor(1).Value
    lBlue = sldColor(2).Value

    'Assign the resultant RGB value to the backcolor
    Me.BackColor = RGB(lRed, lGreen, lBlue)
End Sub
Running the Project
After you enter the code, press F5 to compile and run the program. Then try setting different combinations of the color sliders to see the effect on the color blender.
The Color Blender project works like this: After an initialization process in the Form_Load event, most of the work takes place in the sldColor_Scroll event. As a user moves a slider from the array of Slider controls, the moved slider's index is passed into the sldColor_Scroll event. The application checks the value of the ckGray check box. If it is checked (Value = vbChecked), the value of the moved slider is assigned to all the controls in the slider control array. This causes all the sliders to move to the same position before any other code is executed.
The application then assigns the value from the Value property of each Slider in the sldColor control array to their respective color variableslRed, lGreen, lBlue. The color variables are then passed as parameters to the RGB() function. The return of the RGB() function sets the BackColor property of the form.
Reporting Status and Progress
One of the most important aspects of any program is keeping the users informed about what is going on in the program at any given time. For a program such as a word processor, the users

 
< previous page page_278 next page >